<?php
/* 
	[BuyPg] (C) 2010-2011 Buypg
	$Id: BpAction.php 2011-3-31 17:12:13 wufujun $
 */

if (!defined('THINK_PATH')){
	exit('Access Denied');
}

class BpAction extends Action{
	public $PublicPgsys;
	function _initialize(){
		global $_SGLOBAL , $SeoSet;
		$_SGLOBAL = array();

		//时间
		$mtime = explode(' ', microtime());
		$_SGLOBAL['timestamp'] = $mtime[1];
		$_SGLOBAL['G_starttime'] = $_SGLOBAL['timestamp'] + $mtime[0];

		//GPC过滤
		$magic_quote = get_magic_quotes_gpc();
		if(empty($magic_quote)) {
			$_GET = saddslashes($_GET);
			$_POST = saddslashes($_POST);
		}

		//初始化
		$_SGLOBAL['G_uid'] = 0;
		$_SGLOBAL['G_username'] = '';
		$_SGLOBAL['G_biz'] = '';
		$_SGLOBAL['G_siteid'] = -1;
		$_SGLOBAL['G_siteflag'] = -1;
		$_SGLOBAL['inajax'] = empty($_GET['inajax'])?0:intval($_GET['inajax']);
		$_SGLOBAL['refer'] = empty($_SERVER['HTTP_REFERER'])?'':$_SERVER['HTTP_REFERER'];
		$_SGLOBAL['user_sign'] = 0;

		//处理REQUEST_URI
		if(!isset($_SERVER['REQUEST_URI'])) {
			$_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF'];
			if(isset($_SERVER['QUERY_STRING'])) $_SERVER['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
		}
		if($_SERVER['REQUEST_URI']) {
			$temp = urldecode($_SERVER['REQUEST_URI']);
			if(strexists($temp, '<') || strexists($temp, '"')) {
				$_GET = shtmlspecialchars($_GET);//XSS
			}
		}
		//初始化网站基本信息
		include_once APP_PATH.'/Conf/buypg_config.php';
		//初始网站基本信息赋给全局
		$this->PublicPgsys = $pgsys;
		foreach ($pgsys['sysinfo'] as $key=>$value){
			$this->assign($key , $value);
		}
		$this->assign('sys_set' , $pgsys['sys_set']);
		$this->assign('sys_nav' , $pgsys['sys_nav']);
		//新改版导航
		$this->assign('sys_new_nav',$pgsys['sys_new_nav']);
		$this->assign('sys_search_style' , $pgsys['sys_search_style']);
		//国际购物网站
		$this->assign('arrGuoJiSite' , $arrGuoJiSite);
		//初始化用户后台菜单
		$this->assign('usrcp_menu' , $pgsys['usercp_menu']);
		$this->assign('bizcp_menu' , $pgsys['bizcp_menu']);

		//SEO设置
		$SeoSetModel = M('SeoSet');
		$SeoSet = $SeoSetModel->where('`modelname` = "'.MODULE_NAME.'"')->find();
		$this->assign('SeoSet',$SeoSet);

		//专题菜单
		$this->assign('zhangti_menu' , getRightZT());
		
		//信息提示页默认值
		$this->assign('waitSecond' , 3);
		$this->assign('refer' , $_SGLOBAL['refer']);

		//判断用户登录状态
		checkauth();
		//检测用户签到状态
		$_SGLOBAL['user_sign'] = isUserSign();
		//用户状态模板赋值
		$this->assign('SGLOBAL', $_SGLOBAL);
	}

	//生成验证码
	 public function verify(){
		$type	 =	 isset($_GET['type'])?$_GET['type']:'gif';
        import("@.ORG.Image");
        Image::buildImageVerify(4,1,$type);
    }
	
	// 文件上传
    protected function _upload($model='') {
		global $_SGLOBAL;
        import("@.ORG.UploadFile");
        $upload = new UploadFile();
        //设置上传文件大小
        $upload->maxSize = 3292200;
        //设置上传文件类型
        $upload->allowExts = explode(',', 'jpg,gif,png,jpeg');
        //设置附件上传目录
		$model = $model ? $model."/" : 'buypg/';
		$upload->savePath = APP_PATH.'/attachment/'.$model;
		//设置附件上传子目录
		$upload->autoSub = true;
		$upload->subType = 'date';
		$upload->dateFormat = "Y,m,d";
        //设置需要生成缩略图，仅对图像文件有效
        $upload->thumb = true; 
        // 设置引用图片类库包路径
        $upload->imageClassPath = '@.ORG.Image';
        //设置需要生成缩略图的文件后缀
        $upload->thumbPrefix = 'm,s';  //生产2张缩略图
        //设置缩略图最大宽度
        $upload->thumbMaxWidth = '400,100';
        //设置缩略图最大高度
        $upload->thumbMaxHeight = '400,100';
        //设置上传文件规则
        $upload->saveRule = uniqid;
        //删除原图
        //$upload->thumbRemoveOrigin = true;
        if (!$upload->upload()) {
            //捕获上传异常
            $this->error($upload->getErrorMsg());
        } else {
            //取得成功上传的文件信息
            $uploadList = $upload->getUploadFileInfo();
            import("@.ORG.Image");
            //给m_缩略图添加水印, Image::water('原文件名','水印图片地址')
            //Image::water($uploadList[0]['savepath'].'m_'.$uploadList[0]['savename'], '../Public/Images/logo2.png');
            $_POST['image'] = $uploadList[0]['savename'];
        }
        //$DbAtt = M('Attachment');
        //保存当前数据对象
        //$data['filepath'] = $_POST['image'];
        //$data['dateline'] = $_SGLOBAL['timestamp'];
		//$data['model'] = $model;
        //$list = $DbAtt->add($data);
        if ($_POST['image']) {
            return $_POST['image'];
        } else {
            return false;
        }
    }
}

?>
